const {
    LinValidator,
    Rule
} = require('../../core/lin-validator-v2')

const {
    optionsIdValidator,
    PaginateValidator,
    PositiveIdValidator
} = require('./common')

class addGoodsValidator extends optionsIdValidator { //新增
    constructor() {
        super()
        this.goodName = [
            new Rule('isOptional'),
            new Rule('isLength', '不符合规范', {
                min: 1,
                max: 32
            }),
        ]
        this.price = [
            new Rule('isLength', '不符合规范', {
                min: 1,
                max: 32
            }),
        ]
        this.oldPrice = [
            new Rule('isLength', '不符合规范', {
                min: 1,
                max: 32
            }),
        ]
        this.inventory = [
            new Rule('isLength', '不符合规范', {
                min: 1,
                max: 32
            }),
        ]
        this.sales = [
            new Rule('isLength', '不符合规范', {
                min: 1,
                max: 32
            }),
        ]
        this.introduction = [
            new Rule('isLength', '不符合规范', {
                min: 1,
                max: 32
            }),
        ]
    }
}
class editGoodsValidator extends addGoodsValidator { //修改
    constructor() {
        super()
        this.id = new Rule('isInt', 'id必须为正整数', {
            min: 1
        });
    }
}
class listValidator extends PaginateValidator { //列表

}

class commitBuyOrderValidator extends LinValidator { //提交订单
    constructor() {
        super()
    }
    validateAuths (data) {
        const list = data.body.list;
        if (!Array.isArray(list)) {
            return [false, 'list必须为非空数组'];
        }
        if (list.length < 1) {
            return [false, 'list必须为非空数组'];
        }
        return true;
    }
}

module.exports = {
    addGoodsValidator,
    editGoodsValidator,
    listValidator,
    commitBuyOrderValidator
}